<?php
/**
 * 【里氏替换原则】
 * 子类不能改变父类原有的功能
 * User: Fitz
 * Date: 2018/8/8
 * Time: 18:12
 */

abstract class Shape
{
    protected $width;
    protected $height;

    public function getArea()
    {
        return $this->height * $this->width;
    }

    public function fetch($area)
    {

    }

//    abstract function test();
}

class Square extends Shape
{
    public function __construct($length)
    {
        $this->width = $length;
        $this->height = $length;
    }

    public function setLength($length)
    {
        $this->width = $length;
        $this->height = $length;
    }
}

class Rectangle extends Shape
{
    public function __construct($width, $height)
    {
        $this->width = $width;
        $this->height = $height;
    }

    public function setWidth($width)
    {
        $this->width = $width;
    }

    public function setHeight($height)
    {
        $this->height = $height;
    }
}

function test($array)
{
    /** @var Shape $item */
    foreach ($array as $item) {
        $area = $item->getArea();
        $item->fetch($area);
    }
}

test([new Rectangle(5, 6), new Square(4)]);